<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title></title>
	<!-- 引入element-ui样式 -->
	<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">

</head>
<body>
<div id="case">
	<h2>病例系统</h2>
	<el-row>
		<el-col :span="10">
			<!-- 病例的表单 -->
			<el-form ref="form"  label-width="80px">
				<el-form-item label="身份证件">
					<el-input v-model="patinForm.patientIdCard" @blur="findUserInfo" placeholder="请输入身份证" style="width: 200px;"></el-input>
				</el-form-item>
				<el-form-item label="姓名">
					<el-input v-model="patinForm.patientName" :disabled="true" style="width: 150px;"></el-input>
				</el-form-item>
				<el-form-item label="性别">
					<el-input v-model="patinForm.patientSex" :disabled="true" style="width: 150px;"></el-input>
				</el-form-item>
				<el-form-item label="年龄">
					<el-input v-model="patinForm.patientAge" :disabled="true" style="width: 150px;"></el-input>
				</el-form-item>
				<el-form-item label="出生日期">
					<el-date-picker type="date" :disabled="true" value-format="yyyy-MM-dd" v-model="patinForm.patientBirthday"  style="width: 150px;"></el-date-picker>
				</el-form-item>
				<el-form-item label="联系手机">
					<el-input v-model="patinForm.patientPhoneNumber" style="width: 150px;"></el-input>
				</el-form-item>
				<el-form-item label="联系地址">
					<el-input v-model="patinForm.patientAddress" style="width: 150px;"></el-input>
				</el-form-item>

				<el-form-item label="最后诊断">
					<el-input type="textarea" v-model="caseForm.caseFinalDiagnose"></el-input>
				</el-form-item>

				<el-form-item label="备注">
					<el-input type="textarea" v-model="caseForm.caseComment"></el-input>
				</el-form-item>

				<el-form-item label="是否归档">
					<el-select v-model="caseForm.caseIsPigeonhole" placeholder="请选择是否归档" style="width: 150px;">
						<el-option label="是" value="是"></el-option>
						<el-option label="否" value="否"></el-option>
					</el-select>
				</el-form-item>

				<el-button type="primary" @click="updadeCase(this)">更新病例</el-button>

			</el-form>
		</el-col>
		<el-col :span="12">
			<el-form ref="form"  label-width="80px">
				<el-form-item label="访问时间">
					<el-col :span="11">
						<el-date-picker type="date" placeholder="选择访问时间" value-format="yyyy-MM-dd" v-model="caseForm.caseAccessTime"  style="width: 100%;"></el-date-picker>
					</el-col>
				</el-form-item>
				<el-form-item label="发病时间">
					<el-col :span="11">
						<el-date-picker type="date" placeholder="选择发病时间" value-format="yyyy-MM-dd" v-model="caseForm.caseAttackDate"  style="width: 100%;"></el-date-picker>
					</el-col>
				</el-form-item>
				<el-form-item label="首次患病">
					<el-select v-model="caseForm.caseMorbidity" placeholder="是否为首次患病" style="width: 150px;">
						<el-option label="首发" value="首发"></el-option>
						<el-option label="复发" value="复发"></el-option>
					</el-select>
				</el-form-item>

				<el-form-item label="主治医生">
					<el-input v-model="caseForm.caseCompetentPhysician" placeholder="请输入主治医生" style="width: 200px;"></el-input>
				</el-form-item>



				<el-form-item label="入院诊断">
					<el-input type="textarea" v-model="caseForm.caseInitialDiagnose"></el-input>
				</el-form-item>

				<el-form-item label="出院日期">
					<el-col :span="11">
						<el-date-picker type="date" placeholder="选择出院日期" value-format="yyyy-MM-dd" v-model="caseForm.caseDischargeDate"  style="width: 100%;"></el-date-picker>
					</el-col>
				</el-form-item>

				<el-form-item label="出院状态">
					<el-select v-model="caseForm.caseDischargeCondition" placeholder="请选择出院状态" style="width: 150px;">
						<el-option label="治愈" value="治愈"></el-option>
						<el-option label="好转" value="好转"></el-option>
						<el-option label="未治愈" value="未治愈"></el-option>
						<el-option label="死亡" value="死亡"></el-option>
					</el-select>
				</el-form-item>
			</el-form>
		</el-col>
	</el-row>

</div>


<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<!-- 引入组件库 -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>

<script>
	var app = new Vue({
		el: "#case",
		data: {
			patinForm: {
				patientIdCard: "",
				patientName: "",
				patientPhoneNumber: "",
				patientAddress: "",
				patientSex: "",
				patientAge: "",
				patientBirthday: "",
			},
			caseForm:{
				// 患者身份证
				casePatientIdCard: "",
				casePatientName: "",
				caseSex: "",
				// 访问时间
				caseAccessTime: "",
				caseBirthdate: "",
				caseAge: "",
				casePhoneNumber: "",
				caseAddress: "",
				// 发病时间
				caseAttackDate: "",
				// 首发/次发
				caseMorbidity: "",
				// 入院诊断
				caseInitialDiagnose: "",
				// 主管医生
				caseCompetentPhysician: "",
				// 最后诊断结果 所有病的详情
				caseFinalDiagnose: "",
				// 出院日期
				caseDischargeDate: "",
				// 治愈，好转，未治愈，死亡
				caseDischargeCondition: "",
				// 备注
				caseComment: "",
				// 是否归档
				caseIsPigeonhole: "",
			}
		},
		methods: {
			// 根据身份证查询患者基本信息
			findUserInfo: function() {
				var t = this;
				axios.get('http://192.168.80.13:8080/medical/patient/selectPatientByIdCard', {
					params: {
						idCard: t.patinForm.patientIdCard
					}
				}).then(function(data) {
					if (data.data.success) {
						var d = data.data.data;
						var tp = t.patinForm
						var tc = t.caseForm
						//判断返回的结果
						if(data.data.data==null){
							alert("请输入正确的身份证件")
							return;
						}
						// 给patinForm表单中的数据赋值
						tp.patientName = d.patientName;
						tp.patientSex = d.patientSex;
						tp.patientAge = d.patientAge;
						tp.patientBirthday = d.patientBirthday;
						tp.patientPhoneNumber = d.patientPhoneNumber;
						tp.patientAddress = d.patientAddress;

						// 给caseForm表单中的数据赋值
						tc.casePatientIdCard = tp.patientIdCard;
						tc.casePatientName = d.patientName;
						tc.caseSex = d.patientSex;
						tc.caseAge = d.patientAge;
						tc.caseBirthdate = d.patientBirthday;
						tc.casePhoneNumber = d.patientPhoneNumber;
						tc.caseAddress = d.patientAddress;
						tc.caseIsPigeonhole = "否";
						// 发送请求查询病人病历相关信息
						axios.get('http://192.168.80.13:8080/medical/case/selectCaseByPatientIdCard', {
							params: {
								idCard: t.patinForm.patientIdCard
							}
						}).then(function(data) {
							if (data.data.success) {
								console.log(data.data.data)
								var dd = data.data.data;
								tc.caseFinalDiagnose = dd.caseFinalDiagnose;
								tc.caseComment = dd.caseComment;
								tc.caseAccessTime = dd.caseAccessTime;//访问时间
								tc.caseAttackDate = dd.caseAttackDate;//发病时间
								tc.caseMorbidity = dd.caseMorbidity;//首次患病与否
								tc.caseCompetentPhysician = dd.caseCompetentPhysician;//主管医生
								tc.caseInitialDiagnose = dd.caseInitialDiagnose;//入院诊断
								tc.caseDischargeDate = dd.caseDischargeDate;//出院日期
								tc.caseDischargeCondition = dd.caseDischargeCondition;//出院状态 治愈，好转，未治愈，死亡
								tc.caseIsPigeonhole = dd.caseIsPigeonhole;
							}
						}).catch(function(Error) {
							console.log(Error)
						})

					}


				}).catch(function(Error) {
					console.log(Error)
				})

			},
			updadeCase:function(){
				var t = this;
				if(t.patinForm.patientIdCard==""){
					alert("请输入身份证件！！！！！")
					return;
				}
				var caseForm =t.caseForm
				caseForm.caseBirthdate = caseForm.caseBirthdate.split(" ")[0];
				axios.post('http://192.168.80.9:8080/medical/case/updadeCase', caseForm)
						.then(function(data) {
							if(data.data.success){
								if (t.caseForm.caseIsPigeonhole == "是"){
									alert("归档成功！")
									window.location.href="http://192.168.80.9:8080/case.html";
									return;
								}
								alert("更新成功！")

							}
						}).catch(function(Error) {
					console.log(Error)
				})
			}

		},
		computed: {


		}

	})
</script>


</body>
</html>
